package com.vedana.bankmobile.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class LoadBankDb extends Composite {

	private static LoadBankDbUiBinder uiBinder = GWT
			.create(LoadBankDbUiBinder.class);
	@UiField Button generateBtn;
	@UiField Label statusLabel;
	
	private final LoadBankDbServiceAsync dataService = GWT.create(LoadBankDbService.class);

	interface LoadBankDbUiBinder extends UiBinder<Widget, LoadBankDb> {
	}

	public LoadBankDb() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiHandler("generateBtn")
	void onGenerateBtnClick(ClickEvent event) {
	    dataService.generate(new AsyncCallback<Void>() {
	        public void onFailure(Throwable caught) {
	          statusLabel.setText("Data generation failed");
	          generateBtn.setEnabled(true);
	        }

	        public void onSuccess(Void result) {
	          statusLabel.setText("Data generation succeeded");
	          generateBtn.setEnabled(true);
	        }
	      });
	}
}
